home *** CD-ROM | disk | FTP | other *** search
/ PCMania 75 / PCMania CD75_1.iso / lycos / netscape / netcast.z / ncjs10.jar / vscroll.js < prev    next >
Text File  |  1997-11-26  |  3KB  |  120 lines

  1. <!-- scrolling layers: vertical tab scrolling    -->
  2. <!-- Author:      Tom Pixley                     -->
  3. <!-- Adaptation:  Kyle Sims                      -->
  4. <!-- Math:        Michael Plitkins, Greg Scallan -->
  5. <!-- Modified:    6-26-97                        -->
  6.  
  7. var DRAG_Y, DRAG_lastY, DRAG_dragging;
  8.  
  9. var verticalDragDelta = 0;
  10.  
  11. var tabOffset = 0;
  12. var tabPosition = 0;
  13. var previousTabPosition = 0;
  14.  
  15. var direction = "down";
  16.  
  17. function DRAG_begindrag(e) {
  18.     if (e.which == 1) {
  19.         
  20.         document.captureEvents(Event.MOUSEMOVE);
  21.         DRAG_lastY=e.pageY;
  22.         DRAG_dragging=true;
  23.         return false;
  24.     }
  25.     else {
  26.         /*Do any right mouse button processing here*/
  27.         return true;
  28.     }
  29. }
  30.  
  31. function DRAG_enddrag(e) {
  32.     if (e.which == 1) {
  33.         document.releaseEvents(Event.MOUSEMOVE);
  34.         DRAG_dragging=false;
  35.  
  36.         return false;
  37.     }
  38.     else {
  39.         /*Do any right mouse button processing here*/
  40.         return true;
  41.     }
  42. }
  43.  
  44. function DRAG_drag(e) {
  45.     if (DRAG_dragging) {
  46.         /*This function should only be called if MOUSEMOVEs are captured*/
  47.  
  48.         DRAG_Y = e.pageY;
  49.  
  50.         setPreviousTabPosition(DRAG_Y);
  51.  
  52.         DRAG_lastY=e.pageY;
  53.  
  54.         //scroll content area in increments on mousedrag
  55.         snapContent(direction);
  56.  
  57.         return false;
  58.     }
  59.  
  60.     else {
  61.         return true;
  62.     }
  63. }
  64.  
  65. function recalcTabOffset(Y) {
  66.     //normalize the tab position (negate the length of the tab)
  67.     tabOffset = Y - vTabY;
  68. }
  69.  
  70. function recalcTabPosition(Y, vTabTopLimit) {
  71.     tabPosition = ((Y - vTabTopLimit) - tabOffset) / (vTabRange);
  72. }
  73.  
  74. function setPreviousTabPosition(Y) {
  75.     previousTabPosition = tabPosition;
  76.  
  77.     //determine scrolling direction based on MOUSE position
  78.     if(DRAG_Y < DRAG_lastY) direction = "up";
  79.     else if(DRAG_Y > DRAG_lastY) direction = "down";
  80. }
  81.  
  82. function recalcVerticalDragDelta() {
  83.     //get the delta of the previous and current mouse positions
  84.     verticalDragDelta = (tabPosition - previousTabPosition);
  85. }
  86.  
  87. function recalcContentY() {
  88.     //calculate the new position of the content area layer
  89.     contentY = vddMultiplier * verticalDragDelta;
  90.  
  91.     //convert the new content area layer position to a negative value
  92.     contentY = 0 - contentY;
  93. }
  94.  
  95. function checkTabBounds(Y, vTabTopLimit) {
  96.  
  97.     //if the tab position is not in bounds
  98.     if(tabPosition < 0 || tabPosition > 1) {
  99.         if(tabPosition < 0) {
  100.             tabPosition = 0;
  101.             moveTo(verticalTabLayer.left, vTabTopLimit);
  102.         }
  103.  
  104.         else if(tabPosition > 1) {
  105.             tabPosition = 1;
  106.             moveTo(verticalTabLayer.left, (vTabBottomLimit - vTabH));
  107.         }
  108.     }
  109.  
  110.     //if the tab position is in bounds
  111.     else {
  112.         moveBy(0, Y);
  113.     }
  114. }
  115.  
  116. /*If you want links to work, capture MouseDown and MouseUp separately*/
  117. document.onmousedown=DRAG_begindrag;
  118. document.onmouseup=DRAG_enddrag;
  119. document.onmousemove=DRAG_drag;
  120.